<template>
  <div class></div>
</template>
<script>
import axios from "@/utils/requestzz";

export default {
  name: "APIqueryDbPipenetColSa_003qc",
  components: {},
  data() {
    return {};
  },
  computed: {
    ishistory: function() {
      return this.$store.state.daping.ishistorytime;
    },
    timerangarr: function() {
      return this.$store.state.daping.timepick;
    }
  },
  watch: {
    "$store.state.daping.bigScreen": {
      handler: function(n, o) {
        this.watchEvent();
      }
    }
  },
  mounted() {},
  methods: {
    watchEvent() {
      //先清除定时任务
      if (
        this.$store.state.daping.intervalArr["APIqueryDbPipenetColSa_003qc"] !=
        undefined
      ) {
        return;
      }
      let n_tmp = this.$store.state.daping.bigScreen;
      let g_bigscreen_data_arr = n_tmp.filter(item => {
        if (item.attrName == "echart_plan_heat") {
          return true;
        }
      });
      this.loadData(g_bigscreen_data_arr[0].attrValue);
      let interval = setInterval(() => {
        let n_tmp = this.$store.state.daping.bigScreen;
        let g_bigscreen_data_arr = n_tmp.filter(item => {
          if (item.attrName == "echart_plan_heat") {
            return true;
          }
        });
        this.loadData(g_bigscreen_data_arr[0].attrValue);
      }, this.$root.setting.data.interval);
      this.$store.state.daping.intervalArr["APIqueryDbPipenetColSa_003qc"] = [
        { interval: interval }
      ];
    },
    loadData(val) {
      let queryJson = {
        queries: [
          {
            metric: "*",
            schema: "statistic"
          }
        ],
        table: "pipenet",
        orderBy: "aligntime",
        search: "col_name='sa_003qc'"
      };

      if (this.ishistory == "历史") {
        queryJson = {
          queries: [
            {
              metric: "*",
              schema: "statistic"
            }
          ],
          table: "pipenet",
          type: "history",
          startTime: this.timerangarr[0].getTime(),
          endTime: this.timerangarr[1].getTime(),
          orderBy: "aligntime",
          search: "col_name='sa_003qc'"
        };
      }

      axios.post("/open/queryDb", queryJson).then(res => {
        if (res.data["200"]) {
          //如果有则获取200中的结果
          this.$store.state.daping.queryDbPipenetColSa_003qc = res.data["200"];
        } else {
          //如果没有则提示错误信息 置空对象
          console.log("参数有误", data);
        }
      });
    }
  }
};
</script>
<style lang='scss' scoped>
</style>